/***************************************************************************************************
** WHAT: 	Replication file for the paper
			"Would you fight? We asked aggrieved artisanal miners in Eastern Congo",
			by Nik Stoop and Marijke Verpoorten, published in the Journal of Conflict Resolution
				
			Below you find the code to reproduce the Tables and Figures,
			
** WHEN: 	December '20

** WHO:	 	Nik Stoop, nik.stoop@uantwerp.be
***************************************************************************************************/

clear all
set more off
set scheme s1mono
	
global data "ADD LOCATION WHERE YOU SAVED THE DATABASE"
cap cd "ADD LOCATION WHERE YOU WOULD LIKE TO SAVE GRAPHS AND TABLES"	
	
*** Open database
	use "$data/wyf_jcr.dta",clear

	
*******************************************************************************************************************************
*** FIGURES
*******************************************************************************************************************************

* Figure 1: Mining in Eastern DRC (created in QGIS)

* Figure 2: Intention to fight
	
	*** PANEL A: How likely is it that you would...
		histogram conflict_destroy2 , discrete percent xlabel(0(1)5, labsize(medsmall)valuelabels angle(stdarrow)) title(...destroy Banro property, size(medium)) xtitle("") ytitle ("percent")
		graph save destroy_2,replace
		histogram conflict_attack2 , discrete percent xlabel(0(1)5, labsize(medsmall)valuelabels angle(stdarrow)) title(...attack Banro employees, size(medium)) xtitle("") ytitle ("percent")
		graph save attack_2,replace
		histogram conflict_arms2 , discrete percent xlabel(0(1)5, labsize(medsmall)valuelabels angle(stdarrow)) title(...use fire arms, size(medium)) xtitle("") ytitle ("percent")
		graph save arms_2,replace
		histogram conflict_rebel2 , discrete percent xlabel(0(1)5, labsize(medsmall)valuelabels angle(stdarrow)) title(...join an armed group, size(medium)) xtitle("") ytitle ("percent")
		graph save rebel_2,replace
		graph combine destroy_2.gph attack_2.gph arms_2.gph rebel_2.gph,ycommon 
	
	*** PANEL B: Proxies for the intention to fight
		histogram fight2 , discrete percent xlabel(0(1)1, labsize(medsmall)valuelabels angle(stdarrow)) title(Fight, size(medium)) xtitle("") ytitle ("percent")
		graph save fight2,replace
		histogram fight_rebel2 , discrete percent xlabel(0(1)1, labsize(medsmall)valuelabels angle(stdarrow)) title(Rebel, size(medium)) xtitle("") ytitle ("percent")
		graph save fight_rebel2,replace
		graph combine fight2.gph fight_rebel2.gph,ycommon 
		

* Figure 3: Policy measures to preserve social peace	
		histogram conflict1,  discrete percent xlabel(1(1)5, labsize(small) valuelabels angle(stdarrow)) xtitle(" ") ytitle("share of miners") title("Banro offers employment" "to artisanal miners", size (medsmall))
		graph save c1,replace
		histogram conflict2,  discrete percent xlabel(1(1)5, labsize(small) valuelabels angle(stdarrow)) xtitle(" ") ytitle("share of miners") title("The government adds an AEZ" "in the Chefferie of Wamuzimu", size (medsmall))
		graph save c2,replace
		histogram conflict3,  discrete percent xlabel(1(1)5, labsize(small) valuelabels angle(stdarrow)) xtitle(" ") ytitle(" ") title("The government adds an AEZ" "in the territory of Mwenga", size (medsmall))
		graph save c3,replace
		histogram conflict4,  discrete percent xlabel(1(1)5, labsize(small) valuelabels angle(stdarrow)) xtitle(" ") ytitle(" ") title("The government adds an AEZ" "in the province of South-Kivu", size (medsmall))
		graph save c4,replace
		histogram conflict5,  discrete percent xlabel(1(1)5, labsize(small) valuelabels angle(stdarrow)) xtitle(" ") ytitle(" ") title("Banro autorizes miners to continue ASM" "in selected mining sites", size (medsmall))
		graph save c5,replace
		histogram conflict6,  discrete percent xlabel(1(1)5, labsize(small) valuelabels angle(stdarrow)) xtitle(" ") ytitle(" ") title("Banro develops reorientation programs" "to train miners in other economic activities", size (medsmall))
		graph save c6,replace
		graph combine c1.gph c5.gph c6.gph c2.gph c3.gph c4.gph, xcommon ycommon 


		
*******************************************************************************************************************************
*** TABLES
*******************************************************************************************************************************

* Table 1: Summary statistics
	sum destroy2a attack2a arms2a rebel2a fight2 fight_rebel2 rebelinpit flabor_d fgive_d hpill_d disp_d hurt_d fhurt_d relhurt_d killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_w  op_mediating op_militarization  pdg asset_quint high_educ HHact123 born_kamituga kids10_own age single


* Table 2: Determinants of the intention to fight 
	eststo clear
	local vars "rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
		
	xi:probit fight2 `vars' 
		eststo: margins, dydx (*) post
	xi:probit fight2 `vars' i.carriere, cluster(carriere)
		eststo: margins, dydx (*) post 	
		
		
	xi:probit fight_rebel2 `vars' 	
		eststo: margins, dydx (*) post 		
	xi:probit fight_rebel2 `vars' i.carriere, cluster(carriere)	
		eststo: margins, dydx (*) post 				
		
	esttab using "table_2.rtf", replace b(%6.3f) se(%6.3f) star(* 0.1 ** 0.05 *** 0.01) nogaps label stats(N r2_p,fmt(%9.0fc %9.3f)) drop(_Icar*) ///
	order(rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg _Iasset* high_educ HHact123 born_kamituga kids10_own age single)	
	
	
	
	
*******************************************************************************************************************************
*** APPENDIX
*******************************************************************************************************************************

* Table A1: Using selection on observables to assess bias from unobservables
	*** rebel in pit			
		local vars "killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"

		* fight
		xi:reg fight2 rebelinpit `vars' i.carriere		
		psacalc delta rebelinpit, rmax(0.25)		
		
		* rebel
		xi:reg fight_rebel2 rebelinpit `vars' i.carriere		
		psacalc delta rebelinpit, rmax(0.25)	
	
	*** conflict exposure
		local vars "rebelinpit pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"

		* fight
		xi:reg fight2 killrape_d `vars' i.carriere		
		psacalc delta killrape_d, rmax(0.25) 			
			
		* rebel
		xi:reg fight_rebel2 killrape_d `vars' i.carriere		
		psacalc delta killrape_d, rmax(0.25) 

		
		
		
* Table A2: Intention to Fight		
	eststo clear
	local vars "rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
	local controls "pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"

	xi:probit fight2 rebelinpit killrape_d pos_shikito i.carriere, cluster(carriere)
			eststo: margins, dydx (*) post 		
	xi:probit fight2 rebelinpit killrape_d pos_shikito `controls' i.carriere, cluster(carriere)
			eststo: margins, dydx (*) post 		
	xi:probit fight2 pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization i.carriere, cluster(carriere)
			eststo: margins, dydx (*) post 		
	xi:probit fight2 pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization `controls' i.carriere, cluster(carriere)
			eststo: margins, dydx (*) post 		
	xi:probit fight2 `vars' i.carriere, cluster(carriere)
			eststo: margins, dydx (*) post 
	
	esttab using "table_A2.rtf", replace b(%6.3f) se(%6.3f) star(* 0.1 ** 0.05 *** 0.01) nogaps label stats(N r2_p,fmt(%9.0fc %9.3f)) drop(_Icar*) ///
	order(rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg _Iasset* high_educ HHact123 born_kamituga kids10_own age single)	

	
	
	
* Table A3: Intention to Rebel		
	eststo clear
	local vars "rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
	local controls "pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
			
	xi:probit fight_rebel2 rebelinpit killrape_d pos_shikito i.carriere, cluster(carriere)
			eststo: margins, dydx (*) post 		
	xi:probit fight_rebel2 rebelinpit killrape_d pos_shikito `controls' i.carriere, cluster(carriere)
			eststo: margins, dydx (*) post 		
	xi:probit fight_rebel2 pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization i.carriere, cluster(carriere)
			eststo: margins, dydx (*) post 		
	xi:probit fight_rebel2 pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization `controls' i.carriere, cluster(carriere)
			eststo: margins, dydx (*) post 		
	xi:probit fight_rebel2 `vars' i.carriere, cluster(carriere)	
			eststo: margins, dydx (*) post 		
	
	esttab using "table_A3.rtf", replace b(%6.3f) se(%6.3f) star(* 0.1 ** 0.05 *** 0.01) nogaps label stats(N r2_p,fmt(%9.0fc %9.3f)) drop(_Icar*) ///
	order(rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg _Iasset* high_educ HHact123 born_kamituga kids10_own age single)	

	
		
* Table A4: Wild cluster bootstrap
	eststo clear
	local vars "rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
	eststo f: xi:probit fight2 `vars' i.carriere, cluster(carriere)
	eststo r: xi:probit fight_rebel2 `vars' i.carriere, cluster(carriere)	
	
		* Run regressions & get bootstrapped s.e. in loop
		local est "f r"
		foreach y of local est{
		est restore `y'
		
		* Run boottest to get bootstrapped clustered pvals and CIs for all coefficients
		local indep_vars:colnames e(b)
		local n_vars: colsof e(b)
		local indep_hypotheses
		foreach var of local indep_vars {
		local indep_hypotheses = "`indep_hypotheses' {`var'}"
		}
		boottest `indep_hypotheses',cluster(carriere) nograph weight(webb) seed(202005) //boottest each coefficient
		
		* Store boottest output in e() matrices
		matrix boot_pval  = J(1,`n_vars',.)
		forval k = 1/`n_vars' { //Loop through predictors, aka matrix columns
			matrix boot_pval[1,`k'] = r(p_`k')
		}
		foreach mat in "boot_pval" {
			matrix colnames `mat' = `indep_vars'
			estadd matrix `mat' = `mat': `y'
		}
		}
		* Output boottest
		esttab f r using "Table_A4.rtf", ///
			cells(b(star pvalue(boot_pval) fmt(3)) p(fmt(3)par) boot_pval(fmt(3)par)) replace star(* 0.1 ** 0.05 *** 0.01) nogaps drop(_cons _Icar*) label stats(N r2_p,fmt(%9.0fc %9.3f)) ///
			order(rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg _Iasset* high_educ HHact123 born_kamituga kids10_own age single)	
		
		
			
* Table A5: different estimation methods	
	eststo clear
	local vars "rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
		
	eststo: xi:logit fight2 `vars' i.carriere, cluster(carriere)
		eststo: margins, dydx (*) post 	
	eststo: xi:reg fight2 `vars' i.carriere, cluster(carriere)	
		
	eststo: xi:logit fight_rebel2 `vars' i.carriere, cluster(carriere)
		eststo: margins, dydx (*) post		
	eststo: xi:reg fight_rebel2 `vars' i.carriere, cluster(carriere)	
		
	esttab using "table_A5.rtf", replace b(%6.3f) se(%6.3f) star(* 0.1 ** 0.05 *** 0.01) nogaps label stats(N r2_p r2,fmt(%9.0fc %9.3f)) drop(_cons _Icar*) ///
	order(rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg _Iasset* high_educ HHact123 born_kamituga kids10_own age single)	

	
	
	
* Table A6: Estimated coefficients for conflict exposure indicators
		
		* Fight
		eststo clear
		local vars "rebelinpit pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
		xi:probit fight2 `vars' i.carriere flabor_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight2 `vars' i.carriere fgive_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight2 `vars' i.carriere hpill_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight2 `vars' i.carriere disp_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight2 `vars' i.carriere hurt_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight2 `vars' i.carriere fhurt_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight2 `vars' i.carriere relhurt_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight2 `vars' i.carriere killrape_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		esttab using "table_A6a.rtf", replace b(%6.3f) se(%6.3f) star(* 0.1 ** 0.05 *** 0.01) keep(flabor_d fgive_d hpill_d disp_d hurt_d fhurt_d relhurt_d killrape_d) nogap
		
		
		* Rebel
		eststo clear
		local vars "rebelinpit pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
		xi:probit fight_rebel2 `vars' i.carriere flabor_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight_rebel2 `vars' i.carriere fgive_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight_rebel2 `vars' i.carriere hpill_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight_rebel2 `vars' i.carriere disp_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight_rebel2 `vars' i.carriere hurt_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight_rebel2 `vars' i.carriere fhurt_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight_rebel2 `vars' i.carriere relhurt_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		xi:probit fight_rebel2 `vars' i.carriere killrape_d, cluster(carriere)
		eststo: margins, dydx (*) post 		
		esttab using "table_A6b.rtf", replace b(%6.3f) se(%6.3f) star(* 0.1 ** 0.05 *** 0.01) keep(flabor_d fgive_d hpill_d disp_d hurt_d fhurt_d relhurt_d killrape_d) nogap
	
	

* Table A7: Excluding self-reported former rebels 
	eststo clear	
	local vars "rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
			
	xi:probit fight2 `vars' i.carriere if rebel2!=1, cluster(carriere)
		eststo : margins, dydx (*) post 		
	xi:probit fight_rebel2 `vars' i.carriere if rebel2!=1, cluster(carriere)	
		eststo : margins, dydx (*) post 
			
	esttab using "table_A7.rtf", ///
		cells(b(star fmt(3)) se(fmt(3)par)) replace star(* 0.1 ** 0.05 *** 0.01) nogaps drop(_Icar*) stats(N r2_p,fmt(%9.0fc %9.3f)) ///
		order(rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg _Iasset* high_educ HHact123 born_kamituga kids10_own age single)
	
	
	
	
* Table A8: Four violent actions
	eststo clear
	local vars "rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg i.asset_quint high_educ HHact123 born_kamituga kids10_own age single"
	
	xi:probit destroy2a `vars' i.carriere, cluster(carriere)
	eststo: margins, dydx (*) post 			
	xi:probit attack2a `vars' i.carriere, cluster(carriere)
	eststo: margins, dydx (*) post 			
	xi:probit arms2a `vars' i.carriere, cluster(carriere)
	eststo: margins, dydx (*) post 		
	xi:probit rebel2a `vars' i.carriere, cluster(carriere)
	eststo: margins, dydx (*) post 
	
	esttab using "table_A8.rtf", ///
		cells(b(star fmt(3)) se(fmt(3)par)) replace star(* 0.1 ** 0.05 *** 0.01) nogaps drop(_Icar*) stats(N r2_p,fmt(%9.0fc %9.3f)) ///
		order(rebelinpit killrape_d pos_shikito pos_banro_csr banro_opp2 banro_freq relocate_cheff reservation_wage op_mediating op_militarization pdg _Iasset* high_educ HHact123 born_kamituga kids10_own age single)
		

		
*******************************************************************************************************************************
*** END
*******************************************************************************************************************************
		
		

